package com.chalk.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.chalk.dao.VenueAndSeDao;
import com.chalk.model.VenueAndSe;
import com.chalk.service.VenueAndSeService;
import com.chalk.util.MpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author glq
 * @since 2020-12-10
 */

@Service
public class VenueAndSeServiceImpl extends ServiceImpl<VenueAndSeDao, VenueAndSe> implements VenueAndSeService {


    @Override
    public List<Integer> getSportEventsByVenueId(Integer venueId) {
        List<Integer> integerList = new ArrayList<>();
        //添加构造
        EntityWrapper<VenueAndSe> wrapper = new EntityWrapper<>();
        wrapper.eq("venue_id", venueId);
        List<VenueAndSe> list = selectList(wrapper);
        //过滤到Integer集合
        for (VenueAndSe v : list) {
            integerList.add(v.getSeId());
        }
        return integerList;
    }

    @Override
    public Boolean batchSaveVenueAndSe(List<Integer> seIds, Integer venueId) {
        List<VenueAndSe> venueAndSeList=new ArrayList<>();
        seIds.forEach(integer -> {
            VenueAndSe venueAndSe=new VenueAndSe();
            venueAndSe.setSeId(integer);
            venueAndSe.setVenueId(venueId);
            venueAndSeList.add(venueAndSe);
        });
        return insertBatch(venueAndSeList);
    }

    @Override
    public Boolean deleteVenueAndSe(Integer venueId) {
        EntityWrapper<VenueAndSe> wrapper=new EntityWrapper<>();
        wrapper.eq("venue_id",venueId);
        return delete(wrapper);
    }
}
